package com.sc.rest.controller;

import com.sc.common.pojo.CommonResult;
import com.sc.pojo.TbItem;
import com.sc.pojo.TbItemDesc;
import com.sc.pojo.TbItemParamItem;
import com.sc.rest.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @auther sc
 * @Date 2017/10/27
 */
@Controller
@RequestMapping("/item")
public class ItemController {

    @Autowired
    private ItemService itemService;

    @RequestMapping("/base/{itemId}")
    @ResponseBody
    public CommonResult getItem(@PathVariable(value = "itemId") Long itemId){
        TbItem item = itemService.getItemById(itemId);
        return CommonResult.ok(item);
    }

    @RequestMapping("/desc/{itemId}")
    @ResponseBody
    public CommonResult getItemDesc(@PathVariable(value = "itemId") Long itemId){
        TbItemDesc tbItemDesc =  itemService.getItemDesc(itemId);
        return CommonResult.ok(tbItemDesc);
    }

    @RequestMapping("/param/{itemId}")
    @ResponseBody
    public CommonResult getItemParam(@PathVariable(value = "itemId") Long itemId){
        TbItemParamItem item =  itemService.getItemParam(itemId);
        if(item==null){
            return CommonResult.build(500,"没有此规格信息");
        }
        return CommonResult.ok(item);
    }

}
